﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Text;
using System.Security.Cryptography;
using System.IO;

using CE.Global;
using CE.Promotion;
using CE.Database;
using CE.Mail;
using CE.Configuration;


public partial class WorldCup_football_contest : MyLanguageBasePage
{
    static readonly string PasswordHash = "P@@Sw0rd";
    static readonly string SaltKey = "G1u@yG1uay&KEY";
    static readonly string VIKey = "@g9l8u7a6y524680";
    HtmlMeta language = new HtmlMeta();

    protected void Page_Load(object sender, EventArgs e)
    {
        //string _strWCActive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsWCActive");
        //if (_strWCActive == "0")
        //{
        //    if (Session[CE.Global.General.Guest] == null)
        //    {
        //        Response.Redirect("~/Default.aspx");
        //    }
        //}

        LiteralControl newln = new LiteralControl(Environment.NewLine);
        language.Name = "language";
        language.Content = Resources.Title.PageLanguage;

        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "keywords";
        keywords.Content = Resources.Football.MetaKeyword;
        HtmlMeta description = new HtmlMeta();
        description.Name = "description";
        description.Content = Resources.Football.MetaDescription;

        Page.Header.Controls.AddAt(10, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(11, language);
        Page.Header.Controls.AddAt(12, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(13, keywords);
        Page.Header.Controls.AddAt(14, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(15, description);

        HtmlLink css = new HtmlLink();
        css.Href = Resources.Football.CssFootballUrl;
        css.Attributes["rel"] = "stylesheet";
        css.Attributes["type"] = "text/css";
        css.Attributes["media"] = "all";
        Page.Header.Controls.Add(css);

        HtmlMeta tagTitle = new HtmlMeta();
        tagTitle.Attributes.Add("property", "og:title");
        tagTitle.Content = Resources.Football.WCPageTitle;
        Page.Header.Controls.Add(tagTitle);

        HtmlMeta tagImage = new HtmlMeta();
        tagImage.Attributes.Add("property", "og:image");
        tagImage.Content = MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.ImgScreen;
        Page.Header.Controls.Add(tagImage);

        HtmlMeta tagURL = new HtmlMeta();
        tagURL.Attributes.Add("property", "og:url");
        tagURL.Content = MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.ContestURL;
        Page.Header.Controls.Add(tagURL);

        HtmlMeta tagSite = new HtmlMeta();
        tagSite.Attributes.Add("property", "og:site_name");
        tagSite.Content = "www.gluaygluay.com";
        Page.Header.Controls.Add(tagSite);

        HtmlMeta tagDescription = new HtmlMeta();
        tagDescription.Attributes.Add("property", "og:description");
        tagDescription.Content = Resources.Football.Share;
        Page.Header.Controls.Add(tagDescription);

        Page.Header.Title = Resources.Football.WCPageTitle;
        if (!Page.IsPostBack)
        {
            VerifyFriend();

            tbwUserMobile.WatermarkText = Resources.CarInsurance.MobileSample;
            btnSubmit.ImageUrl = Resources.Football.ImgSubmitBtn;
            txtFriendName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtFriendName1.ClientID + "','" + rfvFriendName1.ClientID + "','" + revFriendName1.ClientID + "');");
            txtEmail1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmail1.ClientID + "','" + rfvEmail1.ClientID + "','" + revEmail1.ClientID + "');");
            txtMobileNo1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtMobileNo1.ClientID + "','" + rfvMobileNo1.ClientID + "','" + revMobileNo1.ClientID + "');");
            txtFriendName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtFriendName2.ClientID + "','" + rfvFriendName2.ClientID + "','" + revFriendName2.ClientID + "');");
            txtEmail2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmail2.ClientID + "','" + revEmail2.ClientID + "','" + revEmail2.ClientID + "');");
            txtMobileNo2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtMobileNo2.ClientID + "','" + rfvMobileNo2.ClientID + "','" + revMobileNo2.ClientID + "');");
            txtFriendName3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtFriendName3.ClientID + "','" + rfvFriendName3.ClientID + "','" + revFriendName3.ClientID + "');");
            txtEmail3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmail3.ClientID + "','" + rfvEmail3.ClientID + "','" + rfvEmail3.ClientID + "');");
            txtMobileNo3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtMobileNo3.ClientID + "','" + rfvMobileNo3.ClientID + "','" + revMobileNo3.ClientID + "');");
            txtUserName.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtUserName.ClientID + "','" + rfvUserName.ClientID + "','" + revUserName.ClientID + "');");
            txtUserMobile.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtUserMobile.ClientID + "','" + rfvUserMobile.ClientID + "','" + revUserMobile.ClientID + "');");
            txtUserEmail.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtUserEmail.ClientID + "','" + rfvUserEmail.ClientID + "','" + revUserEmail.ClientID + "');");

        }
    }

    #region Verify Friend

    private void VerifyFriend()
    {
        Uri theRealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl);
        string rq_wfid = HttpUtility.ParseQueryString(theRealURL.Query).Get("wfid");

        if (rq_wfid != null)
        {
            Int64 _wfid = Convert.ToInt64(Decrypt(rq_wfid.Replace(' ', '+')));
            if (_wfid > 0)
            {
                try
                {
                    MyDatabase _db = new MyDatabase();
                    Int64 _result = -1;
                    string _spName = "sprocWorldCupFriendVerifiedDateSingleItem";

                    SortedList _sPara = new SortedList();
                    _sPara.Add("@WorldCupFriendId", _wfid);
                    _result = _db.ExecuteSP(_spName, _sPara);
                }
                catch
                { }
            }
        }
    }

    #endregion

    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        ChangeValidationEffectServerSide("wcfootball");
        Page.Validate("wcfootball");
        if (Page.IsValid)
        {
            if (txtEmail1.Text.Trim() == txtEmail2.Text.Trim() || txtEmail1.Text.Trim() == txtEmail3.Text.Trim() || txtEmail2.Text.Trim() == txtEmail3.Text.Trim())
            {
                lblErrorMessage.Text = Resources.Football.EnterDifferent;
                return;
            }
            if (!chkAgree.Checked)
            {
                lblErrorMessage.Text = Resources.Football.Pleaseaccept;
                return;
            }
            WorldCupPromotion _worldcupPromotion = new WorldCupPromotion();
            WorldCupPromotionDB _worldcupPromotionDb = new WorldCupPromotionDB();
            if (Session["WorldCupId"] != null)
            {
                _worldcupPromotion.WorldCupUserId = Convert.ToInt32(Session["WorldCupId"].ToString());
            }
            _worldcupPromotion.Name = Server.HtmlEncode(General.ClearScriptTag(txtUserName.Text));
            _worldcupPromotion.Email = txtUserEmail.Text.Trim();
            _worldcupPromotion.Mobile = txtUserMobile.Text;
            Int64 _wpResult = _worldcupPromotionDb.InsertUpdate(_worldcupPromotion);
            if (_wpResult >= 0)
            {
                Session["WorldCupId"] = _wpResult.ToString();

                WorldCupFriendPromotion _worldcupFriend = new WorldCupFriendPromotion();
                WorldCupFriendPromotionDB _worldcupFriendDB = new WorldCupFriendPromotionDB();

                if (hidWCFriendID1.Value != "")
                {
                    _worldcupFriend.WCFriendId = Convert.ToInt32(hidWCFriendID1.Value);
                }
                _worldcupFriend.WCUserId = Convert.ToInt32(Session["WorldCupId"].ToString());
                _worldcupFriend.FriendId = 1;
                _worldcupFriend.Name = txtFriendName1.Text.Trim();
                _worldcupFriend.Email = txtEmail1.Text.Trim();
                _worldcupFriend.Mobile = txtMobileNo1.Text;
                Int64 _wfResult1 = _worldcupFriendDB.Insert(_worldcupFriend);
                if (_wfResult1 > 0)
                {
                    hidWCFriendID1.Value = _wfResult1.ToString();
                }
                _worldcupFriend = null;
                _worldcupFriendDB = null;

                _worldcupFriend = new WorldCupFriendPromotion();
                _worldcupFriendDB = new WorldCupFriendPromotionDB();
                if (hidWCFriendID2.Value != "")
                {
                    _worldcupFriend.WCFriendId = Convert.ToInt32(hidWCFriendID2.Value);
                }
                _worldcupFriend.WCUserId = Convert.ToInt32(Session["WorldCupId"].ToString());
                _worldcupFriend.FriendId = 2;
                _worldcupFriend.Name = txtFriendName2.Text.Trim();
                _worldcupFriend.Email = txtEmail2.Text.Trim();
                _worldcupFriend.Mobile = txtMobileNo2.Text;
                Int64 _wfResult2 = _worldcupFriendDB.Insert(_worldcupFriend);
                if (_wfResult1 > 0)
                {
                    hidWCFriendID2.Value = _wfResult2.ToString();
                }
                _worldcupFriend = null;
                _worldcupFriendDB = null;

                _worldcupFriend = new WorldCupFriendPromotion();
                _worldcupFriendDB = new WorldCupFriendPromotionDB();
                if (hidWCFriendID3.Value != "")
                {
                    _worldcupFriend.WCFriendId = Convert.ToInt32(hidWCFriendID3.Value);
                }
                _worldcupFriend.WCUserId = Convert.ToInt32(Session["WorldCupId"].ToString());
                _worldcupFriend.FriendId = 3;
                _worldcupFriend.Name = txtFriendName3.Text.Trim();
                _worldcupFriend.Email = txtEmail3.Text.Trim();
                _worldcupFriend.Mobile = txtMobileNo3.Text;
                Int64 _wfResult3 = _worldcupFriendDB.Insert(_worldcupFriend);
                if (_wfResult3 > 0)
                {
                    hidWCFriendID3.Value = _wfResult3.ToString();
                }
                _worldcupFriend = null;
                _worldcupFriendDB = null;
                if (hidWCFriendID1.Value == "" || hidWCFriendID2.Value == "" || hidWCFriendID3.Value == "")
                {
                    lblErrorMessage.Text = Resources.Football.RecordNotSave;// "Records not save. Please try again";
                }
                else
                {
                    string _message = "";
                    string _title = "";
                    string _strQuerystring = "?ln=1&";
                    string _strLang = "EN";
                    //HtmlMeta language = new HtmlMeta();
                    if (language.Content.ToString().ToUpper() == "THAI")
                    {
                        _strQuerystring = "?ln=0&";
                        _strLang = "TH";
                    }
                    _title = Resources.Football.EmailTitle;// "GluayGluay.com World Cup 2014 Contest Verification";
                    #region Email Body
                    _message = "<html>";
                    _message += "<head>";
                    _message += "<title></title>";
                    _message += "</head>";
                    _message += "<body class='email_body'>";

                    _message += "<style type='text/css'>";
                    if (_strLang == "TH")
                    {
                        _message += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 1.15em;}";
                    }
                    else if (_strLang == "EN")
                    {
                        _message += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
                    }
                    _message += "a {text-decoration:underline;color:#2c95cc;} ";
                    _message += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
                    _message += "#email_body {width:100%; text-align: left !important;} ";
                    _message += ".email_pad10px {padding:10px;} ";
                    _message += ".email_results td {width:33%;} ";
                    _message += "</style>";

                    _message += "<table border='0' cellspacing='2' cellpadding='0' class='email_body'>";

                    _message += "<tr><td>" + Resources.Football.Dear + " " + Server.HtmlEncode(General.ClearScriptTag(txtUserName.Text)) + ",</td></tr>";
                    _message += "<tr><td>&nbsp;</td></tr>";
                    _message += "<tr><td>" + Resources.Football.EmailMessage + ".</td></tr>";
                    _message += "<tr><td>" + Resources.Football.Please + "&nbsp;<a href='" + MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.VerificationURL + _strQuerystring.ToString() + "wcid=" + Encrypt(Session["WorldCupId"].ToString()) + "' target='_blank'>" + Resources.Football.Clickhere + "</a> " + Resources.Football.Verifyemail + ".</td></tr>";
                    _message += "<tr><td>&nbsp;</td></tr>";
                    _message += "<tr><td><a href='" + MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.ContestURL + "' target='_blank'><img src='" + MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.ImgEmailScreen + "' /></a></td></tr>";
                    _message += "<tr><td>&nbsp;</td></tr>";
                    _message += "<tr><td>" + Resources.Football.BestRegards + "</td></tr>";
                    _message += "<tr><td>&nbsp;</td></tr>";
                    _message += "<tr><td>" + Resources.Football.GGTeam + "</td></tr>";
                    _message += "<tr><td><img alt='' src='http://www.gluaygluay.com/images/v2/logo_gluaygluay.png'></img></td></tr>";

                    _message += "</table>";
                    _message += "</body>";
                    _message += "</html>";
                    #endregion

                    string _emailList = txtUserEmail.Text.Trim();
                    //MyMailManager.SendCRMMessage(_emailList, _title, _message);
                    bool _ismailsent = MyMailManager.SendCRMMessage(_emailList, _title, _message);
                    if (_ismailsent)
                    {
                        if (txtEmail1.Text.Trim() != "") sendEmailToFriend(Server.HtmlEncode(General.ClearScriptTag(txtFriendName1.Text.Trim())), txtEmail1.Text.Trim(), _wfResult1.ToString(), Server.HtmlEncode(General.ClearScriptTag(txtUserName.Text)));
                        if (txtEmail2.Text.Trim() != "") sendEmailToFriend(Server.HtmlEncode(General.ClearScriptTag(txtFriendName2.Text.Trim())), txtEmail2.Text.Trim(), _wfResult2.ToString(), Server.HtmlEncode(General.ClearScriptTag(txtUserName.Text)));
                        if (txtEmail3.Text.Trim() != "") sendEmailToFriend(Server.HtmlEncode(General.ClearScriptTag(txtFriendName3.Text.Trim())), txtEmail3.Text.Trim(), _wfResult3.ToString(), Server.HtmlEncode(General.ClearScriptTag(txtUserName.Text)));
                        //Response.Redirect("/" + Resources.Football.ThankyouURL); //"thankyou.aspx"
                        txtEmail1.Text = "";
                        txtEmail2.Text = "";
                        txtEmail3.Text = "";
                        txtFriendName1.Text = "";
                        txtFriendName2.Text = "";
                        txtFriendName3.Text = "";
                        txtMobileNo1.Text = "";
                        txtMobileNo2.Text = "";
                        txtMobileNo3.Text = "";
                        txtUserEmail.Text = "";
                        txtUserMobile.Text = "";
                        txtUserName.Text = "";
                        divThanksYou.Style.Add("display", "");
                        divContest.Style.Add("display", "none");
                    }
                    else
                        lblErrorMessage.Text = Resources.Football.EmailNotSend;// "Email not send.";
                }
            }
        }
        else
        {
            lblErrorMessage.Text = Resources.Football.CompleteAll;
            return;
        }
    }

    private void sendEmailToFriend(string FrindName, string FrindEmail, string friendId, string UserName)
    {
        try
        {
            string _strLang = "EN";
            //HtmlMeta language = new HtmlMeta();
            if (language.Content.ToString().ToUpper() == "THAI")
            {
                _strLang = "TH";
            }
            string _message = "";
            string _title = "";
            _title = "GluayGluay.com " + Resources.Football.WCTitle;// "GluayGluay.com WORLD CUP 2014 CONTEST";
            #region Email Body
            _message = "<html>";
            _message += "<head>";
            _message += "<title></title>";
            _message += "</head>";
            _message += "<body class='email_body'>";

            _message += "<style type='text/css'>";
            if (_strLang == "TH")
            {
                _message += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 1.15em;}";
            }
            else if (_strLang == "EN")
            {
                _message += ".email_body {background: white;margin: 0;padding: 0;color: #4c4c4c;font-family: Arial, Helvetica, sans-serif;font-size: 0.85em;}";
            }
            _message += "a {text-decoration:underline;color:#2c95cc;} ";
            _message += "#email_container {margin:0 auto;padding:20px;width:600px; height:auto;} ";
            _message += "#email_body {width:100%; text-align: left !important;} ";
            _message += ".email_pad10px {padding:10px;} ";
            _message += ".email_results td {width:33%;} ";
            _message += "</style>";

            _message += "<table border='0' cellspacing='2' cellpadding='0' class='email_body'>";

            _message += "<tr><td>" + Resources.Football.Dear + " " + FrindName + ",</td></tr>";
            _message += "<tr><td>&nbsp;</td></tr>";
            string message1 = Resources.Football.FriendEmail1.Replace("<XXX>", UserName);
            _message += "<tr><td>" + message1 + ".</td></tr>";
            _message += "<tr><td>&nbsp;</td></tr>";
            string message2 = Resources.Football.FriendEmail2.Replace("<XXX>", "<a href='" + MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.ContestURL + "?wfid=" + Encrypt(friendId) + "' target='_blank'>" + Resources.Football.ClickHere2 + "</a> ");
            _message += "<tr><td>" + message2 + ".</td></tr>";
            _message += "<tr><td>&nbsp;</td></tr>";
            _message += "<tr><td><a href='" + MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.ContestURL + "?wfid=" + Encrypt(friendId) + "' target='_blank'><img src='" + MyConfigurationManager.GetAppSettingValue("TH.HostName") + Resources.Football.ImgEmailScreen + "' /></a></td></tr>";
            _message += "<tr><td>&nbsp;</td></tr>";
            _message += "<tr><td>" + Resources.Football.BestRegards + "</td></tr>";
            _message += "<tr><td>&nbsp;</td></tr>";
            _message += "<tr><td>" + Resources.Football.GGTeam + "</td></tr>";
            _message += "<tr><td><img alt='' src='http://www.gluaygluay.com/images/v2/logo_gluaygluay.png'></img></td></tr>";

            _message += "</table>";
            _message += "</body>";
            _message += "</html>";
            #endregion

            bool _ismailsent = MyMailManager.SendCRMMessage(FrindEmail, _title, _message);
        }
        catch
        {
            throw;
        }
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        txtUserName.Text = CE.Global.General.ClearScriptTag(txtUserName.Text.Trim());
        txtUserEmail.Text = HttpUtility.HtmlEncode(txtUserEmail.Text);
        txtUserMobile.Text = HttpUtility.HtmlEncode(txtUserMobile.Text);
        txtFriendName1.Text = CE.Global.General.ClearScriptTag(txtFriendName1.Text.Trim());
        txtEmail1.Text = HttpUtility.HtmlEncode(txtEmail1.Text);
        txtMobileNo1.Text = HttpUtility.HtmlEncode(txtMobileNo1.Text);
        txtFriendName2.Text = CE.Global.General.ClearScriptTag(txtFriendName2.Text.Trim());
        txtEmail2.Text = HttpUtility.HtmlEncode(txtEmail2.Text);
        txtMobileNo2.Text = HttpUtility.HtmlEncode(txtMobileNo2.Text);
        txtFriendName3.Text = CE.Global.General.ClearScriptTag(txtFriendName3.Text.Trim());
        txtEmail3.Text = HttpUtility.HtmlEncode(txtEmail3.Text);
        txtMobileNo3.Text = HttpUtility.HtmlEncode(txtMobileNo3.Text);

        #region user
        //Name
        if (rfvUserName.Enabled && rfvUserName.ValidationGroup == strValidationGroup)
        {
            rfvUserName.Validate();
            if (rfvUserName.IsValid == false)
            {
                txtUserName.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtUserName.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtUserName.ControlStyle.CssClass = "txt-field-1";
        }

        if (revUserName.Enabled && revUserName.ValidationGroup == strValidationGroup)
        {
            if (rfvUserName.IsValid)
            {
                revUserName.Validate();
                if (revUserName.IsValid == false)
                {
                    txtUserName.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtUserName.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtUserName.ControlStyle.CssClass = "txt-field-1";
        }

        //Email
        if (rfvUserEmail.Enabled && rfvUserEmail.ValidationGroup == strValidationGroup)
        {
            rfvUserEmail.Validate();
            if (rfvUserEmail.IsValid == false)
            {
                txtUserEmail.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtUserEmail.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtUserEmail.ControlStyle.CssClass = "txt-field-1";
        }

        if (revUserEmail.Enabled && revUserEmail.ValidationGroup == strValidationGroup)
        {
            if (rfvUserEmail.IsValid)
            {
                revUserEmail.Validate();
                if (revUserEmail.IsValid == false)
                {
                    txtUserEmail.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtUserEmail.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtUserEmail.ControlStyle.CssClass = "txt-field-1";
        }

        //Mobile No
        if (rfvUserMobile.Enabled && rfvUserMobile.ValidationGroup == strValidationGroup)
        {
            rfvUserMobile.Validate();
            if (rfvUserMobile.IsValid == false)
            {
                txtUserMobile.ControlStyle.CssClass = "form validationError";
                tbwUserMobile.WatermarkCssClass = "txt-field-sample validationError";
            }
            else
            {
                txtUserMobile.ControlStyle.CssClass = "txt-field-1";
                tbwUserMobile.WatermarkCssClass = "txt-field-sample";
            }
        }
        else
        {
            txtUserMobile.ControlStyle.CssClass = "txt-field-1";
            tbwUserMobile.WatermarkCssClass = "txt-field-sample";
        }

        if (revUserMobile.Enabled && revUserMobile.ValidationGroup == strValidationGroup)
        {
            if (rfvUserMobile.IsValid)
            {
                revUserMobile.Validate();
                if (revUserMobile.IsValid == false)
                {
                    txtUserMobile.ControlStyle.CssClass = "form validationError";
                    tbwUserMobile.WatermarkCssClass = "txt-field-sample validationError";
                }
                else
                {
                    txtUserMobile.ControlStyle.CssClass = "txt-field-1";
                    tbwUserMobile.WatermarkCssClass = "txt-field-sample";
                }
            }
        }
        else
        {
            txtUserMobile.ControlStyle.CssClass = "txt-field-1";
            tbwUserMobile.WatermarkCssClass = "txt-field-sample";
        }
        #endregion

        #region frind1
        //Name
        if (rfvFriendName1.Enabled && rfvFriendName1.ValidationGroup == strValidationGroup)
        {
            rfvFriendName1.Validate();
            if (rfvFriendName1.IsValid == false)
            {
                txtFriendName1.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtFriendName1.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtFriendName1.ControlStyle.CssClass = "txt-field-1";
        }

        if (revFriendName1.Enabled && revFriendName1.ValidationGroup == strValidationGroup)
        {
            if (rfvFriendName1.IsValid)
            {
                revFriendName1.Validate();
                if (revFriendName1.IsValid == false)
                {
                    txtFriendName1.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtFriendName1.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtFriendName1.ControlStyle.CssClass = "txt-field-1";
        }

        //Email
        if (rfvEmail1.Enabled && rfvEmail1.ValidationGroup == strValidationGroup)
        {
            rfvEmail1.Validate();
            if (rfvEmail1.IsValid == false)
            {
                txtEmail1.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtEmail1.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtEmail1.ControlStyle.CssClass = "txt-field-1";
        }

        if (revEmail1.Enabled && revEmail1.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail1.IsValid)
            {
                revEmail1.Validate();
                if (revEmail1.IsValid == false)
                {
                    txtEmail1.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtEmail1.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtEmail1.ControlStyle.CssClass = "txt-field-1";
        }

        //Mobile No
        if (rfvMobileNo1.Enabled && rfvMobileNo1.ValidationGroup == strValidationGroup)
        {
            rfvMobileNo1.Validate();
            if (rfvMobileNo1.IsValid == false)
            {
                txtMobileNo1.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtMobileNo1.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtMobileNo1.ControlStyle.CssClass = "txt-field-1";
        }

        if (revMobileNo1.Enabled && revMobileNo1.ValidationGroup == strValidationGroup)
        {
            if (rfvMobileNo1.IsValid)
            {
                revMobileNo1.Validate();
                if (revMobileNo1.IsValid == false)
                {
                    txtMobileNo1.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtMobileNo1.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtMobileNo1.ControlStyle.CssClass = "txt-field-1";
        }
        #endregion

        #region frind2
        //Name
        if (rfvFriendName2.Enabled && rfvFriendName2.ValidationGroup == strValidationGroup)
        {
            rfvFriendName2.Validate();
            if (rfvFriendName2.IsValid == false)
            {
                txtFriendName2.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtFriendName2.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtFriendName2.ControlStyle.CssClass = "txt-field-1";
        }

        if (revFriendName2.Enabled && revFriendName2.ValidationGroup == strValidationGroup)
        {
            if (rfvFriendName2.IsValid)
            {
                revFriendName2.Validate();
                if (revFriendName2.IsValid == false)
                {
                    txtFriendName2.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtFriendName2.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtFriendName2.ControlStyle.CssClass = "txt-field-1";
        }

        //Email
        if (rfvEmail2.Enabled && rfvEmail1.ValidationGroup == strValidationGroup)
        {
            rfvEmail2.Validate();
            if (rfvEmail2.IsValid == false)
            {
                txtEmail2.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtEmail2.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtEmail2.ControlStyle.CssClass = "txt-field-1";
        }

        if (revEmail2.Enabled && revEmail2.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail2.IsValid)
            {
                revEmail2.Validate();
                if (revEmail2.IsValid == false)
                {
                    txtEmail2.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtEmail2.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtEmail2.ControlStyle.CssClass = "txt-field-1";
        }

        //Mobile No
        if (rfvMobileNo2.Enabled && rfvMobileNo2.ValidationGroup == strValidationGroup)
        {
            rfvMobileNo2.Validate();
            if (rfvMobileNo2.IsValid == false)
            {
                txtMobileNo2.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtMobileNo2.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtMobileNo2.ControlStyle.CssClass = "txt-field-1";
        }

        if (revMobileNo2.Enabled && revMobileNo2.ValidationGroup == strValidationGroup)
        {
            if (rfvMobileNo2.IsValid)
            {
                revMobileNo2.Validate();
                if (revMobileNo2.IsValid == false)
                {
                    txtMobileNo2.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtMobileNo2.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtMobileNo2.ControlStyle.CssClass = "txt-field-1";
        }
        #endregion

        #region frind3
        //Name
        if (rfvFriendName3.Enabled && rfvFriendName3.ValidationGroup == strValidationGroup)
        {
            rfvFriendName3.Validate();
            if (rfvFriendName3.IsValid == false)
            {
                txtFriendName3.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtFriendName3.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtFriendName3.ControlStyle.CssClass = "txt-field-1";
        }

        if (revFriendName3.Enabled && revFriendName3.ValidationGroup == strValidationGroup)
        {
            if (rfvFriendName3.IsValid)
            {
                revFriendName3.Validate();
                if (revFriendName3.IsValid == false)
                {
                    txtFriendName3.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtFriendName3.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtFriendName3.ControlStyle.CssClass = "txt-field-1";
        }

        //Email
        if (rfvEmail3.Enabled && rfvEmail3.ValidationGroup == strValidationGroup)
        {
            rfvEmail3.Validate();
            if (rfvEmail3.IsValid == false)
            {
                txtEmail3.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtEmail3.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtEmail3.ControlStyle.CssClass = "txt-field-1";
        }

        if (revEmail3.Enabled && revEmail3.ValidationGroup == strValidationGroup)
        {
            if (rfvEmail3.IsValid)
            {
                revEmail3.Validate();
                if (revEmail3.IsValid == false)
                {
                    txtEmail3.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtEmail3.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtEmail3.ControlStyle.CssClass = "txt-field-1";
        }

        //Mobile No
        if (rfvMobileNo3.Enabled && rfvMobileNo3.ValidationGroup == strValidationGroup)
        {
            rfvMobileNo3.Validate();
            if (rfvMobileNo3.IsValid == false)
            {
                txtMobileNo3.ControlStyle.CssClass = "form validationError";
            }
            else
            {
                txtMobileNo3.ControlStyle.CssClass = "txt-field-1";
            }
        }
        else
        {
            txtMobileNo3.ControlStyle.CssClass = "txt-field-1";
        }

        if (revMobileNo3.Enabled && revMobileNo3.ValidationGroup == strValidationGroup)
        {
            if (rfvMobileNo3.IsValid)
            {
                revMobileNo3.Validate();
                if (revMobileNo3.IsValid == false)
                {
                    txtMobileNo3.ControlStyle.CssClass = "form validationError";
                }
                else
                {
                    txtMobileNo3.ControlStyle.CssClass = "txt-field-1";
                }
            }
        }
        else
        {
            txtMobileNo3.ControlStyle.CssClass = "txt-field-1";
        }
        #endregion

    }

    public static string Encrypt(string plainText)
    {
        byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

        byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
        var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
        var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));

        byte[] cipherTextBytes;

        using (var memoryStream = new MemoryStream())
        {
            using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
            {
                cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                cryptoStream.FlushFinalBlock();
                cipherTextBytes = memoryStream.ToArray();
                cryptoStream.Close();
            }
            memoryStream.Close();
        }
        return Convert.ToBase64String(cipherTextBytes);
    }

    public static string Decrypt(string encryptedText)
    {
        byte[] cipherTextBytes = Convert.FromBase64String(encryptedText);
        byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, System.Text.Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
        var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.None };

        var decryptor = symmetricKey.CreateDecryptor(keyBytes, System.Text.Encoding.ASCII.GetBytes(VIKey));
        var memoryStream = new MemoryStream(cipherTextBytes);
        var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
        byte[] plainTextBytes = new byte[cipherTextBytes.Length];

        int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
        memoryStream.Close();
        cryptoStream.Close();
        return System.Text.Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount).TrimEnd("\0".ToCharArray());
    }

}
